//
//  HomeVC.m
//  Logistics
//
//  Created by 恩州科技 on 2018/8/4.
//  Copyright © 2018年 puyue.com. All rights reserved.
//

#import "HomeVC.h"
#import "LXSegmentBtnView.h"
#import "HomePageCell.h"
#import "SupplyGoodsCell.h"
#import "TheDeliveryVC.h"
#import "DesignatedDriverVC.h"
@interface HomeVC ()<LXSegmentBtnViewDelegate,UITableViewDelegate,UITableViewDataSource,ClassTVCellDelegate,HomePageTVCellDelegate>
@property (nonatomic , strong) LXSegmentBtnView *segmentView1;
@property (nonatomic,strong) UITableView * deliveryTV;
@property (nonatomic,strong) UITableView *supplyTV;
@property (nonatomic,strong) UIButton * sendBtn;

//TODO: 要做
//MARK: 标记
//FIXME: 要修改
//WARNING: 这是一个warning
//???: 存在疑问
//!!!: 注意的地方
@end

@implementation HomeVC
-(LXSegmentBtnView *)segmentView1{
    if (!_segmentView1) {
        _segmentView1 = [[LXSegmentBtnView alloc] init];
        _segmentView1.delegate = self;
        _segmentView1.btnBackgroundNormalColor = [UIColor clearColor];
        _segmentView1.btnBackgroundSelectColor = [UIColor colorWithRed:90/255.0 green:158/255.0 blue:230/255.0 alpha:1];
        _segmentView1.titleFont = [UIFont systemFontOfSize:13];
    }
    return _segmentView1;
}
-(UITableView *)deliveryTV {
    if (!_deliveryTV) {
        _deliveryTV = [[UITableView alloc]initWithFrame:CGRectMake(0, kMainTopHeight, kMainScreen_width, kMainScreen_height - kMainTopHeight - GTFixHeightFlaot(37)) style:UITableViewStylePlain];
        _deliveryTV.showsVerticalScrollIndicator = NO;
        _deliveryTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _deliveryTV.dataSource = self;
        _deliveryTV.delegate = self;
    }
    return _deliveryTV;
}
-(UITableView *)supplyTV {
    if (!_supplyTV) {
        _supplyTV = [[UITableView alloc]initWithFrame:CGRectMake(0, kMainTopHeight, kMainScreen_width, kMainScreen_height - kMainTopHeight -GTFixHeightFlaot(37)) style:UITableViewStylePlain];
        _supplyTV.showsVerticalScrollIndicator = NO;
        _supplyTV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _supplyTV.hidden = YES;
        _supplyTV.dataSource = self;
        _supplyTV.delegate = self;
    }
    return _supplyTV;
}
-(UIButton *)sendBtn {
    if (!_sendBtn) {
        _sendBtn = [UIButton buttonWithTitle:@"发货" withImageName:nil withBGColor:[UIColor whiteColor] Withlayer:YES];
        _sendBtn.layer.cornerRadius = GTFixHeightFlaot(20);
        _sendBtn.titleLabel.font = [UIFont systemFontOfSize:GTFixHeightFlaot(13)];
        _sendBtn.layer.borderWidth = 1.0;
        _sendBtn.layer.borderColor = [UIColor grayColor].CGColor;
        [_sendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _sendBtn.frame = CGRectMake(kMainScreen_width/2 - GTFixWidthFlaot(25), kMainScreen_height  - GTFixHeightFlaot(100), GTFixWidthFlaot(40), GTFixHeightFlaot(40));
        [_sendBtn addTarget:self action:@selector(sendBtnClieck:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendBtn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.deliveryTV];
    [self.view addSubview:self.supplyTV];
    [self.view insertSubview:self.sendBtn atIndex:0];
    [self.view bringSubviewToFront:self.sendBtn];
    CGFloat btnW = 80;
    self.segmentView1.frame = CGRectMake((self.view.frame.size.width - btnW*2)/2, 35, btnW*2, 25);
    self.segmentView1.btnTitleArray = @[@"发货中",@"常发货源"];
    [self.navView addSubview:self.segmentView1];
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.deliveryTV) {
         return 8;
    }else{
        return 6;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.deliveryTV) {
        HomePageCell *cell=[tableView dequeueReusableCellWithIdentifier:@"HomePageCell"];
        if (!cell) {
            cell=[[HomePageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomePageCell"];
        }
        cell.indexPath = indexPath;
        cell.delegate = self;
        return cell;
    }else{
        SupplyGoodsCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SupplyGoodsCell"];
        if (!cell) {
            cell=[[SupplyGoodsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SupplyGoodsCell"];
        }
        cell.indexPath = indexPath;
        cell.delegate = self;
        return cell;
    }
}
#pragma  mark --- 发货按钮
-(void)sendBtnClieck:(UIButton *)btn {
    TheDeliveryVC * vc = [TheDeliveryVC new];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma  mark -----发货中cell代理
-(void)subtractwithIndexPath:(NSIndexPath *)index withtype:(NSString *)type{
    if ([type isEqualToString:@"1"]) {
        ZFLog(@"删除");
    }else{
        ZFLog(@"再来一单");
    }
    
}
#pragma  mark -----常发货源cell代理
-(void)homePagewithIndexPath:(NSIndexPath *)index withtype:(NSString *)type {
    if ([type isEqualToString:@"1"]) {
        ZFLog(@"指定司机");
        DesignatedDriverVC * dvc = [DesignatedDriverVC new];
        [self.navigationController pushViewController:dvc animated:YES];
    }else if([type isEqualToString:@"2"]){
        ZFLog(@"刷新置顶");
    }else if([type isEqualToString:@"3"]){
        ZFLog(@"删除");
    }else{
        ZFLog(@"常发货源");
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.deliveryTV) {
         return (GTFixHeightFlaot(110));
    }else{
        return (GTFixHeightFlaot(88));
    }
}
#pragma ---LXSegmentBtnViewDelegate---
-(void)lxSegmentView:(LXSegmentBtnView *)segmentView selectIndex:(NSInteger)selectIndex{
    if (segmentView == self.segmentView1) {
        NSLog(@"delegate ,index = %zd" , selectIndex);
        if (selectIndex == 0) {
            self.deliveryTV.hidden = NO;
            self.supplyTV.hidden = YES;
            self.sendBtn.hidden = NO;
        }else{
            self.deliveryTV.hidden = YES;
            self.supplyTV.hidden = NO;
            self.sendBtn.hidden = YES;
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
